<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>开源技术小栈</title>
</head>
<body>
<h2>如何使用Webman Push服务端私有频道推送</h2>
<script src="/plugin/webman/push/push.js"> </script>
<script>
    /** 1. 创建实例 */
    const connection = new Push({
        url: 'ws://127.0.0.1:8788', // websocket地址
        app_key: '292588aa22ec21634abed93d1318bc1c',
        auth: 'http://122.152.233.192:8787/index/private-auth' // 订阅鉴权(仅限于私有频道)
    });

    /** 2. 订阅私有频道. 假设用户uid为2024 */
    var uid = 2024;
    // 浏览器监听private-user-2024私有频道的消息
    var privateChannel = connection.subscribe('private-user-' + uid);
    // var privateChannel = connection.subscribe('presence-user-' + uid);   //私有频道

    //（3）绑定事件。当private-user-2024 频道有 message 事件的消息时
    privateChannel.on('message', function(data) {
        alert(JSON.stringify(data));
    });
</script>
</body>
</html>